package com.crazyread.imple;

import com.crazyread.dao.BookTypeRankingMapper;
import com.crazyread.dao.CommentMapper;
import com.crazyread.dao.StatisticMapper;
import com.crazyread.model.domain.Book;
import com.crazyread.model.domain.BookTypeRanking;
import com.crazyread.model.domain.Statistic;
import com.crazyread.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StatisticServiceImpl implements StatisticService {
    @Autowired
    StatisticMapper statisticMapper;
    @Autowired
    BookTypeRankingMapper bookTypeRankingMapper;
    @Autowired
    CommentMapper commentMapper;
    @Override
    public void updateStatistics(Book book) {
        Statistic statistic = statisticMapper.selectStatisticByBid(book.getId());
        statistic.setHit(statistic.getHit()+1);
        statisticMapper.updateBookHitsWithId(statistic);
    }

    @Override
    public void delStatistics(Integer book_id) {

    }

    @Override
    public List<Statistic> selectStatistic() {
        return statisticMapper.selectStatistic();
    }

    @Override
    public List<BookTypeRanking> selectBookTypeRanking(int typeid) {
        return bookTypeRankingMapper.selectBookTypeRanking(typeid);
    }

    @Override
    public List<Book> selectBookRanking() {
        return bookTypeRankingMapper.selectBookRanking();
    }
}
